package aop;

import org.aspectj.lang.JoinPoint;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Arrays;
import java.util.Random;

/**
 * @author 黄军艳
 * @version 1.0
 * @date 2024/12/4  16:57
 */
public class LoggerAspect {
    private static final Logger log= LoggerFactory.getLogger(LoggerAspect.class);

    /**
     * 前置增强-打印进入方法和参数
     */
    public void before() {
        log.info("打印机开始自检");
        Random r = new Random();
        int num=r.nextInt(10);
        if (num<5){
            System.out.println("质检成功");
        }else {
            throw new RuntimeException("卡纸异常");
        }
    }
    /**
     * 后置增强-打印 返回结果
     */
    public void afterReturning() {
        log.info("打印成功");
    }

    /**
     * 抛出异常
     */
    public void yc(Exception e) {
        log.info("发生异常："+e.getMessage());
    }
}
